package cn.neusoft.luofa603.yuejian_29.activity;

import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.squareup.picasso.Picasso;

import cn.neusoft.luofa603.yuejian_29.Global;
import cn.neusoft.luofa603.yuejian_29.R;
import cn.neusoft.luofa603.yuejian_29.bean.Training;

public class TrainInfoActivity extends AppCompatActivity {
    private Button bao, iv_return;
    private TextView name, intro, place, price, tel, time;
    private ImageButton train_collect,cal;
    private ImageView train_pic;
    public Training training;
    private String tpic;
    private String tname;
    private String tintro;
    private String tplace;
    private String tprice;
    private String ttel;
    private String ttime;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_traininfo);
        initviews();
        innitEvents();
        intData();
    }

    public void initviews() {
        train_pic = (ImageView) findViewById(R.id.train_pic);
        bao = (Button) findViewById(R.id.bao);
        iv_return = (Button) findViewById(R.id.iv_return);
        name = (TextView) findViewById(R.id.name);
        intro = (TextView) findViewById(R.id.intro);
        price = (TextView) findViewById(R.id.price);
        place = (TextView) findViewById(R.id.place);
        tel = (TextView) findViewById(R.id.tel);
        train_collect = (ImageButton) findViewById(R.id.train_collect);
        time = (TextView) findViewById(R.id.time);
        train_pic = (ImageView) findViewById(R.id.train_pic);
        cal = (ImageButton) findViewById(R.id.cal);

    }

    public void innitEvents() {

        iv_return.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        train_collect.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
        bao.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent intent = new Intent(TrainInfoActivity.this, BuyTrainActivity.class);
                Bundle bundle = new Bundle();
                bundle.putSerializable("Training", training);
                intent.putExtras(bundle);
                startActivity(intent);

            }
        });
        cal.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                //Toast.makeText(TrainInfoActivity.this,"hhhhhhhhhhh",Toast.LENGTH_LONG).show();
                Call();

            }
        });
    }

    public void intData() {
        getTrainInfo();
    }

    public void getTrainInfo() {
        final Bundle bundle = getIntent().getExtras();
        training = (Training) bundle.getSerializable("Training");
        tname = training.getName();
        tintro = training.getIntro();
        tprice = training.getPrice();
        tplace = training.getPlace();
        ttel = training.getTel();
        tpic = training.getThumb();
        ttime = training.getTraintime();
        name.setText(tname);
        intro.setText(tintro);
        price.setText(tprice);
        place.setText(tplace);
        tel.setText(ttel);
        time.setText(ttime);
        Picasso.with(this).load(Global.PIC + tpic).into(train_pic);
    }

    public void Call() {

        Intent intent = new Intent(Intent.ACTION_DIAL);
        if (ttel==null){
            intent.setData(Uri.parse("tel:18041166801"));
        }else{
            intent.setData(Uri.parse("tel:"+ttel));
        }
        startActivity(intent);


    }


}
